/*
 */
package com.mvu.banana.guest.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.dom.client.SpanElement;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;
import com.google.gwt.user.client.ui.Anchor;
import com.google.gwt.user.client.ui.Widget;
import com.mvu.banana.common.client.AsyncCallbackAdapter;
import com.mvu.banana.common.client.CommonComposite;
import com.mvu.banana.common.client.ValueDTO;
import com.mvu.banana.guest.client.gen.UserTileDTO;

/**
 * @generate-server-code
 */
public class UserTile extends CommonComposite{

  interface Binder extends UiBinder<Widget, UserTile> { }
  private static final Binder binder = GWT.create(Binder.class);

  @UiField
  Anchor signOutLink;
  /** @see java.lang.Boolean **/
  public boolean isSigningOut;
  /** @output **/
  @UiField
  public SpanElement username;
  @UiField
  Anchor profileLink;

  public UserTile() {
    super(new UserTileDTO());
    initWidget(binder.createAndBindUi(this));
    get();
  }

  @UiHandler("signOutLink")
  public void signOut(ClickEvent event){
    isSigningOut = true;
    post(signOutLink, new AsyncCallbackAdapter<ValueDTO>() {
      @Override
      protected void afterUpdate(ValueDTO valueDTO) {
        new Guest().go();
      }
    });
  }

  @UiHandler("profileLink")
  public void viewProfile(ClickEvent event){
    new ProfilePage().go();
  }
}
